package com.yimi.yinhepda.utils;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.provider.Settings;
import android.view.View;

import com.pda.uce.commom.util.LogUtil;
import com.pda.uce.commom.util.MyDialog;
import com.pda.ym.utils.AppInfoHelper;
import com.pda.ym.utils.Constants;
import com.pda.ym.utils.SharedPreferUtil;
import com.pda.ym.utils.SoundVibratorManager;
import com.pda.ym.utils.StringUtils;
import com.pda.ym.utils.SysInfo;
import com.yimi.yinhepda.R;
import com.pda.ym.callbacks.UICallBack;
import com.yimi.yinhepda.db.dao.CarPlateTableDao;
import com.yimi.yinhepda.db.dao.JieLiuJianTableDao;
import com.yimi.yinhepda.db.dao.LineVoTableDao;
import com.pda.ym.db.table.CarPlateTable;
import com.yimi.yinhepda.db.table.FuncBtnTable;
import com.yimi.yinhepda.db.table.JieLiuJianTable;
import com.yimi.yinhepda.db.table.LineVoTable;
import com.yimi.yinhepda.downLoadBaseData.DownLoadFile;
import com.yimi.yinhepda.entity.bean.BaseDictEntity;
import com.yimi.yinhepda.entity.bean.CheckBoxItemEntity;
import com.yimi.yinhepda.entity.bean.LoginInfoEntity;
import com.yimi.yinhepda.entity.response.GetUserInfo;
import com.yimi.yinhepda.entity.response.LoadInfo;
import com.yimi.yinhepda.entity.response.QueryBaseDictResponse;
import com.yimi.yinhepda.entity.response.QueryLoadDetailBillcode;
import com.pda.ym.net.NetRequest;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import co.mobiwise.materialintro.shape.Focus;
import co.mobiwise.materialintro.shape.FocusGravity;
import co.mobiwise.materialintro.shape.ShapeType;
import co.mobiwise.materialintro.view.MaterialIntroView;

/**
 * @author 000432
 * @date 2017/4/12
 */
public class Common {
    /**
     * 时效类型：必
     */
    public static final int GOODSP_RIORITY_BI = 10;
    /**
     * 产品类型：时效
     */
    public static final int GOODSP_RIORITY_SHI = 20;
    /**
     * 时效类型：跨越
     */
    public static final int GOODSP_RIORITY_KUA_YUE = 21;
    /**
     * 快递类型
     */
    public static final int UC_WAYBILL_TYPE = 25;
    /**
     * 产品类型：优
     */
    public static final int GOODSP_RIORITY_YOU = 30;
    /**
     * 时效类型：串
     */
    public static final int GOODSP_RIORITY_CHUAN = 40;
    /**
     * 产品类型：标
     */
    public static final int GOODSP_RIORITY_BIAO = 50;
    /**
     * 本地默认产品类型值
     */
    public static final int GOODSP_RIORITY_DEFAULT = 100;
    /**
     * 字符串分隔符：-C-
     */
    public static final String SP_C_ = "-C-";
    /**
     * 用户手机号
     */
    public static final String USER_PHONE = "userPhone";
    /**
     * 登录验证码返回的code
     */
    public static final String VCODE = "vcode";
    /**
     * 旧的托盘任务号
     */
    public static final String OLD_FORLIFT_NO = "oldForliftNo";
    public static final String PLAY_VIBRATOR = "playVibrator";
    /**
     * 自适应屏幕亮度
     */
    public static final String AUTO_LIGHT = "autoLight";
    /**
     * 截留件同步数据的时间
     */
    public static final String JIE_LIU_JIAN_SYNC_TIME = "jieLiuJianSyncTime";
    /**
     * 截留件同步数据的时间
     */
    public static final String UC_ROUTE_DB_SYNC_TIME = "ucRouteDBSyncTime";
    /**
     * 卸车任务类型
     */
    public static final String UNLOAD_TASK_TYPE = "unloadTaskType";
    /**
     * 是否已初始化功能按钮
     */
    public static final String IS_INIT_FUNC = "isInitFunc";
    /**
     * 登录后返回的用户信息
     */
    public static GetUserInfo mGetUserInfo;
    //public static Login mLogin;//登录返回信息
    /**
     * 登录工业平板标志
     */
    public static final String PDT_DEV = "PDT_DEV";
    /**
     * 设备型号
     */
    public static final String DEV_MODEL = "PDT-APAD-P";
    public static final String HAS_UNLOAD_GROUP = "hasUnloadGroup";
    /**
     * 3-装卸工,26-试用，27-外请，28-文员
     */
    public static final String JOB = "job";
    /**
     * 部门类型: 2,3,4分别是一级网点，二级网点，三级网点; 5,6分别是一级分拨，二级分拨
     */
    public static final String DEPT_TYPE = "DeptType";
    public static final String USER_CODE = "UserCode";
    public static final String USER_NAME = "UserName";
    /**
     * 上一部门
     */
    public static final String PRE_DEPT_CODE = "preDeptCode";
    public static final String PRE_DEPT_NAME = "preDeptName";
    public static final String DEPT_CODE = "DeptCode";
    public static final String DEPT_NAME = "DeptName";
    public static final String COMP_CODE = "CompCode";
    public static final String COMP_NAME = "CompName";
    public static final String COOKIE = "CASTGC";
    public static final String OLD_SERVER = "oldServer";
    public static final String OLD_COMPAYN_CODE = "oldCompanyCode";
    /**
     * 蓝牙条码号
     */
    public static final String BLUE_TOOTH_NUM = "blueToothNum";
    /**
     * 装车错分强制确认
     */
    public static final String LOAD_WRONG_FORCE_SURE = "load_wrong_force_sure";
    /**
     * 建包暂存用的日期号
     */
    public static final String DATE_NUM = "dateNum";
    /**
     * 建包暂存用的流水号
     */
    public static final String BUILD_PCK_NUM = "buildPckNum";
    /**
     * 首次使用软件或地址改变
     */
    public static final String ISFIRST = "IsFirst";
    /**
     * 装卸车跳转界面时需要
     */
    public static QueryLoadDetailBillcode mQueryLoadDetailBillcode;
    public static String SUCCESS_SUBMIT_LOAD = "success_submit_load";
    public static LoadInfo mLoadInfo;
    /**
     * 装卸组岗位类型：操作工
     */
    public static final String OPERATOR_EMP = "3";
    /**
     * 装卸组岗位类型：试用
     */
    public static final String TRY_USE_EMP = "26";
    /**
     * 装卸组岗位类型：外请
     */
    public static final String OUT_PLEASE_EMP = "27";
    /**
     * 装卸组岗位类型：文员
     */
    public static final String CLERK_EMP = "28";
    /**
     * 装卸组岗位类型：其他
     */
    public static final String CLERK_OTHER = "-1";
    public static final String DATA_LAST_TIME = "2016-01-01 00:00:00";
    /**
     * 当前场地code
     */
    public static final String PLACE_CODE = "placeCode";
    /**
     * 当期场地名称
     */
    public static final String PLACE_NAME = "placeName";
    /**
     * 移库至场地
     */
    public static final String MOVE_IN_PLACE_NAME = "moveInPlaceName";
    public static final String MOVE_IN_PLACE_CODE = "moveInPlaceCode";
    /**
     * 扫描最后时间 getTime
     */
    public static String SCAN_LAST_TIME = "SCAN_LAST_TIME";
    public static String FUNC_CJPD = "cjpd";
    public static String FUNC_FCJC = "fcjc";
    public static String FUNC_CCFJ = "ccfj";
    public static String FUNC_PSRW = "psrw";
    public static String FUNC_PDLB = "pdlb";
    public static String FUNC_PDCY = "pdcy";
    public static String FUNC_WENTJSB = "wentjsb";
    public static String FUNC_WUTJSB = "wutjsb";
    public static String FUNC_PSTD = "pstd";
    public static String FUNC_DDBD = "ddbd";
    public static String FUNC_YDRK = "ydrk";
    public static String FUNC_CNFJ = "cnfj";
    public static String FUNC_JXCSM = "jxcsm";
    public static String FUNC_LHSM = "lhsm";
    public static String FUNC_YCGL = "ycgl";
    public static String FUNC_JBGL = "jbgl";
    public static String FUNC_YKDH = "ykdh";
    public static String FUNC_QDGL = "qdgl";
    public static String FUNC_FBZT = "fbzt";
    public static String FUNC_CWSB = "cwsb";
    public static String FUNC_AJSM = "ajsm";
    public static String FUNC_XJSM = "xjsm";
    public static String FUNC_HLJSM = "hljsm";
    public static String FUNC_LCFJ = "lcfj";
    public static String FUNC_CCSB = "ccsb";
    public static String FUNC_SJSM = "sjsm";
    public static String FUNC_RCSM = "rcsm";
    public static String FUNC_SMZYS = "smzys";
    public static String FUNC_JBSM = "JBSM";
    public static String FUNC_LJSM = "LJSM";
    public static String FUNC_LCSM = "LCSM";
    public static String FUNC_HDDJSM = "HDDJSM";
    public static String FUNC_HDFJSM = "HDFJSM";
    public static String FUNC_WDJJSM = "WDJJSM";
    public static String FUNC_PJSM = "PJSM";
    public static String FUNC_ZHDJSM = "ZHDJSM";
    public static String FUNC_YJDD = "YJDD";
    public static String FUNC_SFSM = "SFSM";
    public static String FUNC_DPSM = "DPSM";
    public static String FUNC_JBASM = "JBASM";
    public static String FUNC_HLJASM = "HLJASM";
    public static String FUNC_SJIANSM = "SJIANSM";
    public static String FUNC_YJLC = "YJLC";
    public static String FUNC_AJIANSM = "AJIANSM";
    public static String FUNC_XXFSM = "XXFSM";
    public static String FUNC_TJSM = "TJSM";
    public static String FUNC_CWEISB = "CWEISB";
    public static String FUNC_CCCX = "CCCX";
    public static String FUNC_KJGZ = "KJGZ";
    public static String FUNC_FCSM = "FCSM";
    public static String FUNC_SCTJ = "SCTJ";
    public static String FUNC_JBCZ = "JBCZ"; //建包操作
    public static String FUNC_JBCZV = "JBCZV";//解包操作
    public static String FUNC_GROUP_OPTER_CODE = "operationMoudle";
    public static String FUNC_GROUP_OPTER = "操作模块";
    public static String FUNC_GROUP_INSIDE_CODE = "insideOperation";
    public static String FUNC_GROUP_INSIDE = "场内操作";
    public static String FUNC_GROUP_EXCEPTION_CODE = "exceptionManage";
    public static String FUNC_GROUP_EXCEPTION = "异常管理";
    /**
     * 同行卸车（跨越卸车）
     */
    public static String FUNC_KYDH = "kydh";
    /**
     * 常用添加按钮code
     */
    public static String FUNC_ADD = "func_add";
    /**
     * 扫描类型：跨越到达点货
     */
    public static int SCAN_TYPE_KUAYUE_SPOTGOODS = 9;
    /**
     * 扫描类型：融合装车
     */
    public static int SCAN_TYPE_MERGE_LOAD = 10;
    /**
     * 扫描类型：融合卸车
     */
    public static int SCAN_TYPE_MERGE_UNLOAD = 11;
    /**
     * 跨越任务key
     */
    public static String KUAYUE_TASK_KEY = "kuaYueTask";

    /**
     * 装卸车扫描上传条数
     */
    public static int SCAN_UPLOAD_NUM = 10;
    /**
     * 打卡开关，默认1-旧功能,0-新功能
     */
    public static int BREAK_CARD_SWITCH = 1;
    /**
     * 自提扫描上传条数
     */
    public static int ZITI_SCAN_UPLOAD_NUM = 10;
    /**
     * 分拨自提扫描类型
     */
    public static final int FEN_BO_ZI_TI_SCAN_TYPE = 8;
    /**
     * 数据库压缩文件
     */
    public static final String DB_ZIP_FILE = "ym-pda-yh.zip";
    /**
     * zip密码
     */
    public static final String ZIP_PWD = "yimidida";
    public static final String EXCUTE_TEMP_DB = "excuteTempDB_1";

    //判断是否是正整数
    public static boolean isPositiveInteger(String number) {
        String rex = "^[0-9]*[1-9][0-9]*$";
        Pattern p = Pattern.compile(rex);
        Matcher m = p.matcher(number);
        if (m.find()) {
            return true;
        }
        return false;
    }

    //判断是否是重量
    public static boolean isWeight(String number) {
        String rex = "^[0-9]+([.]{1}[0-9]+){0,1}$";
        Pattern p = Pattern.compile(rex);
        Matcher m = p.matcher(number);
        if (m.find()) {
            return true;
        }
        return false;
    }

    /**
     * 在线程池中 初始化车牌数据
     */
    public static void initCarPalteData(Context context) {
        List<CarPlateTable> carPlateTables = new ArrayList<>();
        String[] pShirt = context.getResources().getStringArray(R.array.province_short);
        for (int i = 1; i <= pShirt.length; i++) {
            carPlateTables.add(new CarPlateTable(i, pShirt[i - 1], 0));
        }
        if (!carPlateTables.isEmpty()) {
            CarPlateTableDao carPlateTableDao = new CarPlateTableDao();
            List<CarPlateTable> allCarPlates = carPlateTableDao.getAllData();
            if (allCarPlates != null) {
                if (carPlateTables.size() > allCarPlates.size()) {
                    //有新增的车牌时，则更新数据
                    carPlateTableDao.createOrUpdate(carPlateTables);
                }
            }
        }
    }

    /**
     * 判断路由是否错分
     * 返回：false 没有错分
     * 返回：true 有错分
     */
    public static boolean waybillRouteWrong(String routeInfo, String nextStationCode) {
        if (nextStationCode == null) {
            nextStationCode = "";
        }
        if (routeInfo == null) {
            routeInfo = "";
        }
        boolean flag = false;
        String[] routeInfo_part = routeInfo.split("-");
        //下一站在路由信息中，没有路由错分，flag为false
        for (int i = 0; i < routeInfo_part.length; i++) {
            if (nextStationCode.equals(routeInfo_part[i])) {
                flag = false;
                break;
            } else {
                flag = true;
            }
        }
        return flag;
    }

    /**
     * 装车使用
     * 判断路由是否错分
     * 返回：false 没有错分
     * 返回：true 有错分
     */
    public static boolean waybillRouteWrongForLoad(String routeInfo, String nextStationCode, String currentStationCode) {
        if (nextStationCode == null) {
            nextStationCode = "";
        }
        if (routeInfo == null) {
            routeInfo = "";
        }
        if (currentStationCode == null) {
            currentStationCode = "";
        }
        boolean flag = false;
        String[] routeInfo_part = routeInfo.split("-");
        //下一站在路由信息中，没有路由错分，flag为false
        for (int i = 0; i < routeInfo_part.length; i++) {
            if (nextStationCode.equals(routeInfo_part[i])) {
                flag = false;
                break;
            } else {
                flag = true;
            }
        }
        //路由没错分时，判断路由是否逆向
        if (!flag) {
            //路由当前位置
            int currentIndex = 0;
            //路由下一站位置
            int nextIndex = 0;
            for (int i = 0; i < routeInfo_part.length; i++) {
                if (currentStationCode.equals(routeInfo_part[i])) {
                    currentIndex = i;
                } else if (nextStationCode.equals(routeInfo_part[i])) {
                    nextIndex = i;
                }
            }
            //下一站位置小于等于当前站位置时，路由为逆向
            if (nextIndex <= currentIndex) {
                flag = true;
            }
        }
        return flag;
    }

    /**
     * 货物路由不包含本站，返回false,否则true
     */
    public static boolean waybillRouteNoInRouteInfo(String routeInfo, List<String> currentStationCodes) {
        if (routeInfo == null) {
            routeInfo = "";
        }
        if (currentStationCodes == null || currentStationCodes.size() == 0) {
            return false;
        }
        String[] routeInfo_part = routeInfo.split("-");
        //当前站在路由信息中，返回true
        for (String routeItem : routeInfo_part) {
            for (String currentRoute : currentStationCodes) {
                if (routeItem.equals(currentRoute)) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * 新手引导工具
     */
    public static void showIntro(Activity activity, View view, String text, String usageId) {
        new MaterialIntroView.Builder(activity)
                .enableDotAnimation(true)
                //.enableIcon(true)
                .setFocusGravity(FocusGravity.CENTER)
                .setFocusType(Focus.MINIMUM)
                .setDelayMillis(200)
                .enableFadeAnimation(true)
                .performClick(true)
                .setInfoText(text)
                .setTarget(view)
                .setShape(ShapeType.RECTANGLE)
                //THIS SHOULD BE UNIQUE ID
                .setUsageId(usageId)
                .show();
    }

    /**
     * 上传PDA后台管理登录信息
     *
     * @param online 1-在线，2-离线
     */
    public static void uploadPdaManagerLogInfo(Context context, int online) {
        SharedPreferUtil sharedPreferUtil = SharedPreferUtil.getInstance();
        LoginInfoEntity loginInfoEntity = new LoginInfoEntity();
        loginInfoEntity.setCompCode(sharedPreferUtil.getCompanyCode());
        loginInfoEntity.setCompName(sharedPreferUtil.getCompanyName());
        // 2,3,4分别是一级网点，二级网点，三级网点; 5,6分别是一级分拨，二级分拨
        int deptType = sharedPreferUtil.getIntValue(Common.DEPT_TYPE);
        if (deptType == 5 || deptType == 6) {
            loginInfoEntity.setDeptType(2);
        } else if (deptType == 2 || deptType == 3 || deptType == 4) {
            loginInfoEntity.setDeptType(1);
        }
        loginInfoEntity.setPreDeptCode(sharedPreferUtil.getValue(Common.PRE_DEPT_CODE));
        loginInfoEntity.setPreDeptName(sharedPreferUtil.getValue(Common.PRE_DEPT_NAME));
        loginInfoEntity.setCurrentDeptCode(sharedPreferUtil.getDeptCode());
        loginInfoEntity.setCurrentDeptName(sharedPreferUtil.getValue(Common.DEPT_NAME));
        //设置在线状态：1-在线，2-离线
        loginInfoEntity.setOnLine(online);
        loginInfoEntity.setUserCode(sharedPreferUtil.getValue(Common.USER_CODE));
        loginInfoEntity.setUserWorkNum(sharedPreferUtil.getWorkNum());
        loginInfoEntity.setUserName(sharedPreferUtil.getValue(Common.USER_NAME));
        loginInfoEntity.setLoginLastTime((new Date()).getTime());
        loginInfoEntity.setCurrentPdaVersion(AppInfoHelper.getAppVersion(context));
        loginInfoEntity.setCurrentPdaVersionName(AppInfoHelper.getAppVersionName(context));
        loginInfoEntity.setNewPdaVersion(sharedPreferUtil.getIntValue(Constants.NEW_PAD_VERSION));
        loginInfoEntity.setNewPdaVersoinName(sharedPreferUtil.getValue(Constants.NEW_PDA_VERSION_NAME));
        loginInfoEntity.setPdaBrand(SysInfo.getInstance().getManufacturer());
        loginInfoEntity.setPdaModel(SysInfo.getInstance().getPhoneModel());
        loginInfoEntity.setDevId(SysInfo.getInstance().getImei());
        loginInfoEntity.setMacAddress(SysInfo.getInstance().getMacAddr());
        loginInfoEntity.setDevOsVersion(SysInfo.getInstance().getOsVersion());

        new NetRequest().setMethod(NetRequest.Method.POST_STRING)
                .setResponsClazz(Object.class)
                .setUrl(Constants.URL_PDA_MANAGER_LOGIN_INFO)
                .setRequestObject(loginInfoEntity)
                .setConnTimeOut(5 * 1000)
                .execute(new UICallBack() {
                    @Override
                    public void onError(String msg) {
                        LogUtil.e(msg);
                    }

                    @Override
                    public void onSuccess(Object obj) {
                    }
                });
    }

    public static void showPermissionDialog(final Context context, String msg, final Integer requestCode) {
        MyDialog dialog = new MyDialog(context);
        dialog.setIcon(R.drawable.alert);
        dialog.setDialogType(MyDialog.DialogType.ALERT_DIALOG);
        dialog.setTitle("提示");
        dialog.setMessage(msg);
        dialog.setPositiveClickListener("去打开", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                Uri packageURI = Uri.parse("package:" + context.getPackageName());
                Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, packageURI);
                if (requestCode == null) {
                    context.startActivity(intent);
                } else {
                    ((Activity) context).startActivityForResult(intent, requestCode);
                }
            }
        });
        dialog.setNegativeClickListener(R.drawable.btn_login_selector, "取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int i) {
                dialog.dismiss();
            }
        });
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        dialog.show();
    }

    /**
     * 个性配置
     */
    public static void specificSetting(Context context) {
        //触屏震动开关
        boolean playVirbator = SharedPreferUtil.getInstance().getBooleanValue(Common.PLAY_VIBRATOR);
        if (playVirbator) {
            SoundVibratorManager.playVibrator(context, 30);
        }
    }

    /**
     * 跳转至优速app
     */
    public static void goToUCApp(final Context context) {
        final Intent intent = new Intent();
        intent.setAction("cn.uce.pda.loginMain");
        intent.putExtra("isYiMiPDA", true);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        if (context.getPackageManager().resolveActivity(intent, 0) != null) {
            MyDialog dialog = new MyDialog(context);
            dialog.setIcon(R.drawable.alert);
            dialog.setDialogType(MyDialog.DialogType.ALERT_DIALOG);
            dialog.setTitle("提示");
            dialog.setMessage("是否进入快递PDA？");
            dialog.setPositiveClickListener("是", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    context.startActivity(intent);
                }
            });
            dialog.setNegativeClickListener(R.drawable.btn_login_selector, "否", null);
            dialog.setCanceledOnTouchOutside(false);
            dialog.setCancelable(false);
            dialog.show();
        } else {
            //提示安装优速快递APP
            MyDialog dialog = new MyDialog(context);
            dialog.setIcon(R.drawable.alert);
            dialog.setDialogType(MyDialog.DialogType.ALERT_DIALOG);
            dialog.setTitle("提示");
            dialog.setMessage("请先安装快递PDA，是否下载安装？");
            dialog.setPositiveClickListener("是", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    DownLoadFile.getInstance(context).downloadUCAPP();
                }
            });
            dialog.setNegativeClickListener(R.drawable.btn_login_selector, "否", null);
            dialog.setCanceledOnTouchOutside(false);
            dialog.setCancelable(false);
            dialog.show();
        }
    }

    /**
     * 设置功能背景图片
     */
    public static void setFuncPic(List<FuncBtnTable> list, boolean isEditPage) {
        if (list != null) {
            list = setFuncPic(list);
            if (!isEditPage) {
                if (!list.isEmpty()) {
                    if (list.size() < 4 && !list.get(list.size() - 1).getNameCode().equals(Common.FUNC_ADD)) {
                        list.add(new FuncBtnTable("", Common.FUNC_ADD, 1, list.size() + 1, R.mipmap.func_add));
                    }
                }
            }
        }
    }

    /**
     * 设置功能背景图片
     */
    public static List<FuncBtnTable> setFuncPic(List<FuncBtnTable> list) {
        if (list != null) {
            for (FuncBtnTable item : list) {
                if (item.getNameCode().equals(Common.FUNC_CJPD)) {
                    item.setPicId(R.mipmap.create_check);
                } else if (item.getNameCode().equals(Common.FUNC_FCJC)) {
                    item.setPicId(R.mipmap.check_balance);
                } else if (item.getNameCode().equals(Common.FUNC_CCFJ)) {
                    item.setPicId(R.mipmap.cache_fenjian);
                } else if (item.getNameCode().equals(Common.FUNC_PSRW)) {
                    item.setPicId(R.mipmap.dispatch_task);
                } else if (item.getNameCode().equals(Common.FUNC_PDLB)) {
                    item.setPicId(R.mipmap.check_list);
                } else if (item.getNameCode().equals(Common.FUNC_PDCY)) {
                    item.setPicId(R.mipmap.check_diff);
                } else if (item.getNameCode().equals(Common.FUNC_WENTJSB)) {
                    item.setPicId(R.mipmap.problem_report);
                } else if (item.getNameCode().equals(Common.FUNC_WUTJSB)) {
                    item.setPicId(R.mipmap.nohead_report);
                } else if (item.getNameCode().equals(Common.FUNC_PSTD)) {
                    item.setPicId(R.mipmap.dispatch_back);
                } else if (item.getNameCode().equals(Common.FUNC_DDBD)) {
                    item.setPicId(R.mipmap.single_bind);
                } else if (item.getNameCode().equals(Common.FUNC_YDRK)) {
                    item.setPicId(R.mipmap.waybill_stock);
                } else if (item.getNameCode().equals(Common.FUNC_CNFJ)) {
                    item.setPicId(R.mipmap.in_site_sort);
                } else if (item.getNameCode().equals(Common.FUNC_JXCSM)) {
                    item.setPicId(R.mipmap.old_unload_scan);
                } else if (item.getNameCode().equals(Common.FUNC_LHSM)) {
                    item.setPicId(R.mipmap.lan_huo_scan);
                } else if (item.getNameCode().equals(Common.FUNC_YCGL)) {
                    item.setPicId(R.mipmap.exception_manage);
                } else if (item.getNameCode().equals(Common.FUNC_JBGL)) {
                    item.setPicId(R.mipmap.create_packge_manage);
                } else if (item.getNameCode().equals(Common.FUNC_JBCZ)) {
//                    item.setPicId(R.mipmap.jian_bao);
                } else if (item.getNameCode().equals(Common.FUNC_JBCZV)) {
//                    item.setPicId(R.mipmap.jiebao);
                } else if (item.getNameCode().equals(Common.FUNC_YKDH)) {
                    item.setPicId(R.mipmap.move_stock);
                } else if (item.getNameCode().equals(Common.FUNC_QDGL)) {
                    item.setPicId(R.mipmap.sign_manage);
                } else if (item.getNameCode().equals(Common.FUNC_FBZT)) {
                    item.setPicId(R.mipmap.fenbo_ziti);
                } else if (item.getNameCode().equals(Common.FUNC_KYDH)) {
                    item.setPicId(R.mipmap.tonghangxieche);
                } else if (item.getNameCode().equals(Common.FUNC_CWSB)) { //仓位上报
                    item.setPicId(R.mipmap.cangwei_upload);
                } else if (item.getNameCode().equals(Common.FUNC_AJSM)) { //安检扫描
                    item.setPicId(R.mipmap.anjian_scan);
                } else if (item.getNameCode().equals(Common.FUNC_XJSM)) { //小件扫描
                    item.setPicId(R.mipmap.light_casting);
                } else if (item.getNameCode().equals(Common.FUNC_HLJSM)) { //回流件扫描
                    item.setPicId(R.mipmap.huiliujian);
                } else if (item.getNameCode().equals(Common.FUNC_CCSB)) { //差错上报
                    item.setPicId(R.mipmap.mistake_upload);
                } else if (item.getNameCode().equals(Common.FUNC_SJSM)) { //收件扫描
                    item.setPicId(R.mipmap.shoujian_scan);
                } else if (item.getNameCode().equals(Common.FUNC_RCSM)) { //入仓扫描
                    item.setPicId(R.mipmap.rucang_scan);
                } else if (item.getNameCode().equals(Common.FUNC_SMZYS)) { //实名制验收
                    item.setPicId(R.mipmap.shiming_yanshou);
                } else if (item.getNameCode().equals(Common.FUNC_JBSM)) { //建包扫描
                    item.setPicId(R.mipmap.jian_bao);
                } else if (item.getNameCode().equals(Common.FUNC_LCSM) || item.getNameCode().equals(Common.FUNC_LCFJ)) { //留仓扫描 留仓发件
                    item.setPicId(R.mipmap.liucang_scan);
                } else if (item.getNameCode().equals(Common.FUNC_HDDJSM)) { //回单到件
                    item.setPicId(R.mipmap.huidan_daojian);
                } else if (item.getNameCode().equals(Common.FUNC_HDFJSM)) { //回单发件
                    item.setPicId(R.mipmap.huidan_fajian);
                } else if (item.getNameCode().equals(Common.FUNC_HDDJSM)) { //网点交接
                    item.setPicId(R.mipmap.wangdian_jiaojie);
                } else if (item.getNameCode().equals(Common.FUNC_HDDJSM)) { //派件扫描
                    item.setPicId(R.mipmap.paijian_scan);
                } else if (item.getNameCode().equals(Common.FUNC_HDDJSM)) { //找货登记
                    item.setPicId(R.mipmap.look_goods);
                } else if (item.getNameCode().equals(Common.FUNC_HDDJSM)) { //一键到达
                    item.setPicId(R.mipmap.yijian_arrive);
                } else if (item.getNameCode().equals(Common.FUNC_HDDJSM)) { //收发扫描
                    item.setPicId(R.mipmap.shoufa_scan);
                } else if (item.getNameCode().equals(Common.FUNC_HDDJSM)) { //到派扫描
                    item.setPicId(R.mipmap.daopai_scan);
                } else if (item.getNameCode().equals(Common.FUNC_JBASM)) { //解包扫描
                    item.setPicId(R.mipmap.jiebao);
                } else if (item.getNameCode().equals(Common.FUNC_YJLC)) { //一键留仓
                    item.setPicId(R.mipmap.yijian_liucang);
                } else if (item.getNameCode().equals(Common.FUNC_XXFSM)) { //小信封扫描
                    item.setPicId(R.mipmap.xiao_xin_feng_scan);
                } else if (item.getNameCode().equals(Common.FUNC_TJSM)) { //退件扫描
                    item.setPicId(R.mipmap.tuijian_scan);
                } else if (item.getNameCode().equals(Common.FUNC_CCCX)) { //差错查询
                    item.setPicId(R.mipmap.mistake_query);
                } else if (item.getNameCode().equals(Common.FUNC_KJGZ)) { //快件跟踪
                    item.setPicId(R.mipmap.kuaijian_genzong);
                } else if (item.getNameCode().equals(Common.FUNC_FCSM)) { //复称扫描
                    item.setPicId(R.mipmap.kuaiyun_fucheng);
                } else if (item.getNameCode().equals(Common.FUNC_SCTJ)) { //上传统计
                    item.setPicId(R.mipmap.upload_statictis);
                } else {
                    item.setPicId(R.mipmap.nohead_report);
                }
            }
        }
        return list;
    }

    /**
     * s
     * 查询数据字典装卸车扫描条数：scan_upload_num
     */
    public static void queryDictScanUploadNum() {
        Map<String, String> params = new HashMap<>(2);
        params.put("dictCode", "scan_upload_num");
        //查询类型，1-只查询未作废的，为null则查询所有(包含作废和未作废的)
        params.put("type", "1");

        new NetRequest().setMethod(NetRequest.Method.GET)
                .setResponsClazz(QueryBaseDictResponse.class)
                .setUrl(Constants.URL_QUERY_DICT)
                .setParams(params)
                .execute(new UICallBack() {
                    @Override
                    public void onError(String msg) {
                        ToastUtil.showToast(msg);
                    }

                    @Override
                    public void onSuccess(Object obj) {
                        QueryBaseDictResponse response = (QueryBaseDictResponse) obj;
                        if (response != null && response.getData() != null) {
                            List<BaseDictEntity> dictlist = response.getData();
                            if (dictlist != null && !dictlist.isEmpty()) {
                                BaseDictEntity entity = dictlist.get(0);
                                try {
                                    Common.SCAN_UPLOAD_NUM = Integer.parseInt(entity.getDictValue());
                                } catch (NumberFormatException e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                    }
                });
    }

    /**
     * 判断是否是截留件
     *
     * @param result 快递运单号
     */
    public static boolean isJieLiuJian(Context context, String result, JieLiuJianTableDao jieLiuJianDao) {
        //判断是否是截留件
        JieLiuJianTable jieLiuJianTable = jieLiuJianDao.queryWaybillNo(result);
        if (jieLiuJianTable != null && result.equals(jieLiuJianTable.getBillCode())
                && "1".equals(jieLiuJianTable.getOperateStatus())) {
            //操作状态，1-未处理，2-已处理
            if ("jieliujian".equals(jieLiuJianTable.getNosPdaMark())) {
                //截留件
                MyDialog.showAlertDialog(context, "此单截留，请在NOS-截留件管理中处理！");
            } else if ("lanjiejian".equals(jieLiuJianTable.getNosPdaMark())) {
                //拦截件
                MyDialog.showAlertDialog(context, "运单为拦截件请在NOS中转管理-扫描管理-截留件管理中处理！");
            } else {
//                ToastUtil.showToast("未知截留件");
                return false;
            }
            SoundVibratorManager.playSound(2);
            return true;
        }
        return false;
    }

    /**
     * 二级排序类型 必-时-串-快递-空
     */
    public static String getSecondType(int type) {
        if (type == Common.GOODSP_RIORITY_BI) {
            return "必";
        } else if (type == Common.GOODSP_RIORITY_SHI) {
            return "时";
        } else if (type == Common.GOODSP_RIORITY_CHUAN) {
            return "串";
        } else if (type == Common.UC_WAYBILL_TYPE) {
            return "快递";
        } else if (type == Common.GOODSP_RIORITY_KUA_YUE) {
            return "跨";
        } else {
            return "";
        }
    }

    /**
     * 设置二级排序：必-时-跨-串-快递-空
     */
    public static int setSecondType(String productType, String goodsPriority, String waybillNo) {
        if ("CP24".equals(productType) || "CP13".equals(productType)) {
            //产品类型：时
            return Common.GOODSP_RIORITY_SHI;
        } else if (goodsPriority != null) {
            //1-必，2-串，3-标,4-跨越
            if ("1".equals(goodsPriority)) {
                return Common.GOODSP_RIORITY_BI;
            } else if ("2".equals(goodsPriority)) {
                return Common.GOODSP_RIORITY_CHUAN;
            } else if ("4".equals(goodsPriority)) {
                return Common.GOODSP_RIORITY_KUA_YUE;
            }
        } else if (UcWaybillValidate.validate(waybillNo)) {
            //快递运单
            return Common.UC_WAYBILL_TYPE;
        }
        return Common.GOODSP_RIORITY_DEFAULT;
    }

    /**
     * 查询下一站线路（用于复选框选择）
     */
    public static List<CheckBoxItemEntity> queryNextDeptLines() {
        List<LineVoTable> lines = new LineVoTableDao().findSourceZoneCode(SharedPreferUtil.getInstance().getDeptCode());
        List<CheckBoxItemEntity> checkNextList = getDestLineList(lines);
        return ListUtils.removeDublipate(checkNextList);
    }

    /**
     * 查询上一站线路（用于复选框选择）
     */
    public static List<CheckBoxItemEntity> queryPreviousDeptLines() {
        List<LineVoTable> lines = new LineVoTableDao().findDestZoneCode(SharedPreferUtil.getInstance().getDeptCode());
        List<CheckBoxItemEntity> checkNextList = getSourceLineList(lines);
        return ListUtils.removeDublipate(checkNextList);
    }

    public static List<CheckBoxItemEntity> getDestLineList(List<LineVoTable> lines) {
        List<CheckBoxItemEntity> checkNextList = new ArrayList<>();
        for (LineVoTable item : lines) {
            CheckBoxItemEntity entity = new CheckBoxItemEntity();
            entity.setName(item.getDestZoneName());
            entity.setCode(item.getDestZoneCode());
            checkNextList.add(entity);
        }
        return checkNextList;
    }

    public static List<CheckBoxItemEntity> getSourceLineList(List<LineVoTable> lines) {
        List<CheckBoxItemEntity> checkNextList = new ArrayList<>();
        for (LineVoTable item : lines) {
            CheckBoxItemEntity entity = new CheckBoxItemEntity();
            entity.setName(item.getSourceZoneName());
            entity.setCode(item.getSourceZoneCode());
            checkNextList.add(entity);
        }
        return checkNextList;
    }

    /**
     * 运单类型
     *
     * @return 0-未知类型，1-快运，2-快递
     */
    public static int getWaybillType(String waybillNo) {
        if (StringUtils.isWaybillNo(waybillNo) || StringUtils.isPackgeNo(waybillNo)) {
            return 1;
        } else if (UcWaybillValidate.validate(waybillNo)) {
            return 2;
        } else {
            return 0;
        }
    }

    /**
     * 数据字典查询
     */
    public static void queryDictionary(String dictCode, UICallBack callBack) {
        Map<String, String> params = new HashMap<>(2);
        params.put("dictCode", dictCode);
        params.put("type", "1");

        new NetRequest().setMethod(NetRequest.Method.GET)
                .setResponsClazz(QueryBaseDictResponse.class)
                .setUrl(Constants.URL_QUERY_DICT)
                .setParams(params)
                .execute(callBack);
    }

    /**
     * 数据字典：融合装车扫描创建任务（merge_load_scan_create_task）
     */
    public static void queryMergeLoadScanCreateTask() {
        SharedPreferUtil.getInstance().setBooleanValue(Constants.MERGE_LOAD_SCAN_TASK_SWITCH, false);
        queryDictionary("merge_load_scan_create_task", new UICallBack() {
            @Override
            public void onError(String msg) {
                ToastUtil.showToast(msg);
            }

            @Override
            public void onSuccess(Object obj) {
                QueryBaseDictResponse response = (QueryBaseDictResponse) obj;
                if (response != null && response.getData() != null) {
                    List<BaseDictEntity> dicts = response.getData();
                    if (!dicts.isEmpty()) {
                        BaseDictEntity dictEntity = dicts.get(0);
                        SharedPreferUtil.getInstance().setBooleanValue(Constants.MERGE_LOAD_SCAN_TASK_SWITCH,
                                dictEntity.getDictValue().equals("1"));
                    }
                }
            }
        });
    }

}
